#include "svgwindow.h"

SvgWindow::SvgWindow(QWidget* parent):QScrollArea(parent){
    svgWidget = new SvgWidget;
    setWidget(svgWidget);
}
void SvgWindow::setFile(QString fileName){
    svgWidget->load(fileName);      // 加载svg图像
    QSvgRenderer* render = svgWidget->renderer();   // 获取图像尺寸
    svgWidget->resize(render->defaultSize());
}

void SvgWindow::mouseMoveEvent(QMouseEvent *event){
    mousePressPos = event->pos();
    scrollBarValuesOnMousePress.rx() = horizontalScrollBar()->value();
    scrollBarValuesOnMousePress.ry() = verticalScrollBar()->value();
    event->accept();
}

void SvgWindow::mousePressEvent(QMouseEvent *event){
    horizontalScrollBar()->setValue(scrollBarValuesOnMousePress.x() - event->pos().x() + mousePressPos.x());
    verticalScrollBar()->setValue(scrollBarValuesOnMousePress.y() - event->pos().y() + mousePressPos.y());
    horizontalScrollBar()->update();
    verticalScrollBar()->update();
    event->accept();
}



